/**
 * Created by HUAKANG on 2017/5/10.
 */
/**
 * 理财师 app 使用记录
 */
var comValidform = null;
var returnStatus = false;
var statistics = {
    curPage : 1,
    pageSize : 10,
    dataCache : null,
    totalInfo : null,

    // 设置分页
    setPageChange : function(delCurPage) {
        var url = 'mgr/StatisticsCtrl/queryFinancialDetail';

        if (typeof (pageIdx) != "undefined") {
            statistics.curPage = pageIdx;
        }

        var startTime = $.trim($('#searchModForm input[name="startTime"]')
            .val());
        var endTime = $.trim($('#searchModForm input[name="endTime"]').val());

        var params = {
            'curPage' : statistics.curPage,
            'pageSize' : 999999,
            'startTime' : startTime,
            'endTime' : endTime
        };

        var cb = function(data) {
            if (data.resultCode == 200) {
                var totalCount = data.size;
                var pageTotal = (totalCount / statistics.pageSize > 0) ? Math
                    .ceil(totalCount / statistics.pageSize) : 1;
                pageHelper.init(pageTotal, totalCount, statistics.search,
                    delCurPage); // 翻页事件
            }
        };
        sendApiNoLoad(url, params, cb, 'POST');
    },

    // 查询
    search : function(pageIdx) {
        var url = 'mgr/StatisticsCtrl/queryFinancialDetail';
        if (typeof (pageIdx) != "undefined") {
            statistics.curPage = pageIdx;
        }

        var startTime = $.trim($('#searchModForm input[name="startTime"]')
            .val());
        var endTime = $.trim($('#searchModForm input[name="endTime"]').val());

        var params = {
            'curPage' : statistics.curPage,
            'pageSize' : statistics.pageSize,
            'startTime' : startTime,
            'endTime' : endTime
        };

        var cb = function(data) {
            $('#tableList tbody').empty();
            var tr = '';
            if (data.resultCode == 200) {
                if (data.result != null && data.result.length > 0) {

                    // 输出全部内容
                    for (var i = 0; i < data.result.length; i++) {
                        var singleObj = data.result[i];
                        tr += '<tr><td>'
                            + (i + 1) + '</td><td>'
                            + singleObj.name + '</td><td>'
                            + singleObj.realName + '</td><td>'
                            + singleObj.userOrgName + '</td><td>'
                            + singleObj.company + '</td><td>'
                            + singleObj.job + '</td><td>'
                            + singleObj.created + '</td>'
                            + '</tr>';
                    }
                }

            } else {
                tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
            }

            $('#tableList tbody').html(tr);
        };
        sendApiNoLoad(url, params, cb, 'POST');
    },

    bindEvent : function() {
        // 查询
        $('#searchData').click(function() {
            statistics.curPage = 1;
            statistics.setPageChange(null);
            statistics.search();
        });

        $('#excel').on('click', function() {
            var startTime = $.trim($('#searchModForm input[name="startTime"]')
                .val());
            var endTime = $.trim($('#searchModForm input[name="endTime"]').val());
            var url = '/mgr/StatisticsCtrl/queryFinancialDetailExcel?startTimeStr=' + startTime + '&endTimeStr=' + endTime;
            location.href = url;
        });
    },

    init : function() {
        jsUtils.controlFunctionBtn();
        statistics.search();
        statistics.bindEvent();
        statistics.setPageChange(null);
    }
}
$(document).ready(function() {
    statistics.init();
});
function submitForm() {
    comValidform.submitForm();
    return returnStatus;
}